<template>
    <div class="my_ambient_search">
        <div class="left">
            <div class="left_item">
                <div class="button button1" @click="store.openambientAdd">
                    <img src="@/assets/home/add.png" style="width: 24px;height: 24px;" alt="">
                    <div style="margin-left: 8px">新建环境</div>
                </div>
            </div>
            <!-- <div class="left_item">
                <div class="button">
                    批量导入
                </div>
            </div>
            <div class="left_item">
                <div class="button">
                    打 开
                </div>
            </div>
            <div class="left_item">
                <el-dropdown placement="bottom" trigger="click">
                    <div class="button">
                        <div>关 闭</div>
                        <div class="select_img"></div>
                    </div>
                    <template #dropdown>
                        <el-dropdown-menu>
                            <el-dropdown-item>关闭已选</el-dropdown-item>
                            <el-dropdown-item>关闭所有</el-dropdown-item>
                        </el-dropdown-menu>
                    </template>
</el-dropdown>
</div>
<div class="left_item">
    <el-dropdown placement="bottom" trigger="click">
        <div class="button">
            <div>更 多</div>
            <div class="select_img"></div>
        </div>
        <template #dropdown>
                        <el-dropdown-menu>
                            <el-dropdown-item>批量更新环境</el-dropdown-item>
                            <el-dropdown-item>批量更新Cookie</el-dropdown-item>
                            <el-dropdown-item>批量导出</el-dropdown-item>
                            <el-dropdown-item>分组管理</el-dropdown-item>
                        </el-dropdown-menu>
                    </template>
    </el-dropdown>
</div> -->
        </div>
        <div class="right">
            <div class="right_item">
                <div class="button" @click="store.getEnvironmentList()">
                    <div class="shuaxing_img"></div>
                </div>
            </div>
            <div class="right_item">
                <div class="button">
                    窗口排列
                </div>
            </div>
            <div class="right_item">
                <el-input v-model="state.filterCondition.value" style="max-width: 300px" placeholder="请输入"
                    :prefix-icon="Search" class="input-select">
                    <template #prepend>
                        <el-select v-model="state.filterCondition.type" @change="state.filterCondition.value = ''"
                            style="width: 100px">
                            <el-option v-for="item in state.filterSelect" :key="item.field" :label="item.label"
                                :value="item.value" />
                        </el-select>
                    </template>
                </el-input>
            </div>
            <div class="right_item">
                <div class="button" @click="state.filterDrawer.show = true">
                    <div class="filter_img" style="margin-right: 8px;"></div>
                    <div>筛 选</div>
                </div>
            </div>
            <div class="right_item">
                <!-- <img src="@/assets/home/filter2.png" style="width: 14px;height: 14px;" alt=""> -->
                <el-dropdown placement="bottom-end" trigger="click" popper-class="sort_dropdown_popper">
                    <img src="@/assets/home/filter2.png" style="width: 14px;height: 14px;" alt="">
                    <template #dropdown>
                        <el-dropdown-menu>
                            <el-dropdown-item v-for="item in state.sortRoleMap" :key="item.value" class="sort_dropdown"
                                :class="item.value == state.sortRole ? 'sort_dropdown_active' : ''" @click="changeSortRole(item.value)">
                                <div>{{ item.label }}</div>
                                <div class="yes_icon" v-if="item.value == state.sortRole"></div>
                            </el-dropdown-item>
                        </el-dropdown-menu>
                    </template>
                </el-dropdown>
            </div>
        </div>
    </div>
</template>

<script setup>
const { store, state } = inject('storejs')
import { Search } from '@element-plus/icons-vue'

const changeSortRole = (value) => {
    state.sortRole = value
    store.getEnvironmentList()
}
</script>

<style lang="scss" scoped>
.my_ambient_search {
    display: flex;
    justify-content: space-between;

    .left {
        display: flex;
        justify-content: flex-start;

        .left_item {
            margin-right: 8px;
            display: flex;
            align-items: center;

            .button1 {
                background-color: #3569fd;
                border: 1px solid #3569fd;
                color: #fff;
                font-size: 16px;
            }

            .button1:hover {
                color: #fff !important;
            }
        }
    }

    .right {
        display: flex;
        justify-content: flex-end;

        .right_item {
            margin-left: 8px;
            display: flex;
            align-items: center;
        }
    }
}

.button {
    display: flex;
    height: 32px;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
    font-size: 14px;
    border-radius: 2px;
    cursor: pointer;
    border: 1px solid #d9d9d9;
    color: #1d2129;
    // font-weight: 600;

    .select_img {
        margin-left: 8px;
        width: 14px;
        height: 14px;
        background: url('@/assets/home/down.png');
        background-size: cover;
    }

    .shuaxing_img {
        width: 14px;
        height: 14px;
        background: url('@/assets/home/shuaxin.png');
        background-size: cover;
    }

    .filter_img {
        width: 14px;
        height: 14px;
        background: url('@/assets/home/filter.png');
        background-size: cover;
    }


}

.button:hover {
    border-color: #3569fd;
    color: #3569fd;

    .select_img {
        margin-left: 8px;
        width: 14px;
        height: 14px;
        background: url('@/assets/home/down_hover.png');
        background-size: cover;
    }

    .shuaxing_img {
        width: 14px;
        height: 14px;
        background: url('@/assets/home/shuaxin_hover.png');
        background-size: cover;
    }

    .filter_img {
        width: 14px;
        height: 14px;
        background: url('@/assets/home/filter_hover.png');
        background-size: cover;
    }
}

.yes_icon {
    width: 16px;
    height: 16px;
    background: url('@/assets/home/yes_hover.png');
    background-size: cover;
}
</style>

<style>
.input-select .el-select__selected-item {
    display: flex;
    justify-content: center;
    font-size: 14px !important;
    color: #1d2129 !important;
    font-weight: 100;
    background-color: #fafafa;
}

.input-select .el-select__wrapper {
    background-color: #fafafa !important;
    border-radius: 2px;
}

.sort_dropdown_popper {
    width: 150px;
}

.sort_dropdown {
    color: #1d2129;
    font-size: 14px;
    padding: 5px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sort_dropdown_active {
    color: #3569fd !important;
}
</style>